package com.kcsj.service.user;

import com.kcsj.dao.User.RoleAssResourceDao;
import com.kcsj.domain.user.Resource;
import com.kcsj.domain.user.RoleAssResource;
import com.kcsj.util.JdbcHelper;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
/**
 * @author 胡庆阳
 * 29th Nov. 2020
 */
public class RoleAssResourceService {

    private static final RoleAssResourceDao roleAssResourceDao
            = RoleAssResourceDao.getInstance();
    private static final RoleAssResourceService roleAssResourceService
            =new RoleAssResourceService();
    private RoleAssResourceService(){}

    public static RoleAssResourceService getInstance(){
        return roleAssResourceService;
    }

    public Collection<Resource> findRoleMenu(Integer id) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        Collection<Resource> resources = roleAssResourceDao.findRoleMenu(id, conn);
        JdbcHelper.close(conn);
        return resources;
    }


    public Collection<Integer> findRoleResourceAndAuthorityIds(Integer id) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        Collection<Integer> allAuthorityIds = roleAssResourceDao.findRoleResourceAndAuthorityIds(id, conn);
        JdbcHelper.close(conn);
        return allAuthorityIds;
    }



    public void update(RoleAssResource roleAssResource) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        roleAssResourceDao.update(roleAssResource, conn);
        JdbcHelper.close(conn);
    }

}
